package com.yic.module.mes.dal.mysql.modetail;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.mes.dal.dataobject.modetail.MoDetailDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.mes.controller.admin.modetail.vo.*;

/**
 * 工单明细 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface MoDetailMapper extends BaseMapperX<MoDetailDO> {

    default PageResult<MoDetailDO> selectPage(MoDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MoDetailDO>()
                .eqIfPresent(MoDetailDO::getMoId, reqVO.getMoId())
                .eqIfPresent(MoDetailDO::getMoSn, reqVO.getMoSn())
                .eqIfPresent(MoDetailDO::getItemSn, reqVO.getItemSn())
                .eqIfPresent(MoDetailDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MoDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MoDetailDO::getId));
    }

    default List<MoDetailDO> selectList(MoDetailExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MoDetailDO>()
                .eqIfPresent(MoDetailDO::getMoId, reqVO.getMoId())
                .eqIfPresent(MoDetailDO::getMoSn, reqVO.getMoSn())
                .eqIfPresent(MoDetailDO::getItemSn, reqVO.getItemSn())
                .eqIfPresent(MoDetailDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MoDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MoDetailDO::getId));
    }

    default int deleteByMoId(Long moId) {
        return delete(new LambdaQueryWrapperX<MoDetailDO>()
                .eq(MoDetailDO::getMoId, moId));
    }
    default List<MoDetailDO> selectByMoSn(Collection<String> sns) {
        return selectList(new LambdaQueryWrapperX<MoDetailDO>()
                .inIfPresent(MoDetailDO::getMoSn, sns));
    }

    default MoDetailDO selectByMoAndSn(Long moId, String serialNo) {
        return selectOne(new LambdaQueryWrapperX<MoDetailDO>()
                .eq(MoDetailDO::getMoId, moId)
                .eq(MoDetailDO::getMoSn, serialNo));
    }

    default MoDetailDO selectBySn(String serialNo) {
        return selectOne(new LambdaQueryWrapperX<MoDetailDO>()
                .eq(MoDetailDO::getMoSn, serialNo));
    }
}
